<?php
header("Content-Type:json/html;charset=utf8;");

$config = require '../config.php';
$conn = new mysqli($config['servername'], $config['username'], $config['password'], $config['dbname']);
require "../validToken.php";
$info = isValidToken($conn);

if($info['status']){
    $base64_body = substr(strstr($_POST['myBase64'],','),1);
    $data= base64_decode($base64_body );
    $filename="images/dabai_".time().".jpg";///要生成的图片名字
    file_put_contents($filename,$data);
    $result = ['code' =>1, 'data' =>  array(
        'src' => 'upload/'.$filename,
    ),  'msg' => "保存图片成功!"];
    require "../util/savelog.php";
    saveLog($conn, $info['user']['id'], "上传了一张图片");
}
else{
    $result = ['code' =>0,
     'msg' => "token验证失败!"];
}
print_r(json_encode($result));
